package com.qingyun.house.api;

import com.qingyun.house.api.config.NewRuleConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@SpringBootApplication
@EnableDiscoveryClient
@Controller
@RibbonClient(name = "user", configuration = NewRuleConfig.class)
public class ApiGetawayApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiGetawayApplication.class, args);
    }

    @Autowired
    public DiscoveryClient discoveryClient;

    @ResponseBody
//    @RequestMapping(value = "/get")
    @RequestMapping(value = "index1")
    public List<ServiceInstance> getRegister() {
        return discoveryClient.getInstances("user-service");
    }
}
